/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 17655
 * Date: 2025-01-17
 * Time: 10:32
 */
public class test1 {
    /*
    LeetCode 202 快乐数
     */

    public boolean isHappy(int n) {
        int slow = n;
        int fast = getNext(n);
        while(fast!=1 && slow!=fast){
            slow = getNext(slow);
            fast = getNext(getNext(fast));
        }
        return fast==1;
    }

    public int getNext(int n){
        int total = 0;
        while(n>0){
            int d = n%10;
            n /=10;
            total = total+d*d;
        }
        return total;
    }
}
